<template>
  <div>
    <div class="box">
      <div class="chex">
        <!-- <input type="checkbox" v-model="checked" :id="item.id" /> -->
        <van-checkbox
          v-model="checked"
          icon-size="16px"
          checked-color="red"
        ></van-checkbox>
      </div>
      <div class="jpg">
        <img :src="item.img" alt="" />
      </div>
      <div class="boxContent">
        <p>
          <span class="qh" v-if="!item.isHave">缺货</span>
          <span class="zy" v-if="item.isDirect">直营</span>
          <span class="title">{{ item.name }}</span>
        </p>
        <div class="boxBottom">
          <span class="price">￥{{ item.price }}</span>
          <div class="btnAll">
            <button @click="deleFn">-</button>
            <span>{{ num }}</span>
            <button @click="addFn">+</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    item: Object,
    act: Boolean,
  },
  data() {
    return {
      num: 1,
      checked: false,
    };
  },
  methods: {
    deleFn() {
      if (this.num <= 1) {
        this.num = 1;
      } else {
        this.num--;
      }
    },
    addFn() {
      this.num++;
    },
  },
  watch: {
    checked() {
      // console.log("组件里面的id：" + this.item.id);
      this.$emit(
        "countFn",
        this.item.price,
        this.num,
        this.checked,
        this.item.id
      );
    },
    num() {
      this.$emit(
        "countFn",
        this.item.price,
        this.num,
        this.checked,
        this.item.id
      );
    },
    act() {
      // console.log(this.act);
      this.checked = this.act;
    },
  },
  computed: {},
};
</script>

<style scoped lang="less">
.box {
  width: 100%;
  height: 130px;
  background-color: #fff;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e5e5e5;
  .chex {
    padding: 0 10px;
  }
  .jpg {
    width: 112px;
    height: 112px;
    img {
      width: 100%;
    }
  }
  .boxContent {
    flex: 1;
    height: 112px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    p {
      .qh {
        font-size: 13px;
        padding: 0 5px;
        width: 36px;
        height: 18px;
        background-color: #909090;
        color: #fff;
        text-align: center;
        display: inline-block;
      }
      .zy {
        font-size: 13px;
        padding: 0 5px;
        width: 36px;
        height: 18px;
        background-color: #d81e06;
        color: #fff;
        text-align: center;
        display: inline-block;
      }
      .title {
        font-size: 16px;
        color: #333;
      }
    }
    .boxBottom {
      display: flex;
      justify-content: space-between;

      .price {
        color: #d81e06;
        font-size: 18px;
        line-height: 32px;
      }
      .btnAll {
        button {
          border: none;
          width: 40px;
          text-align: center;
          display: inline-block;
          background-color: transparent;
        }
        span {
          background-color: #eee;
          padding: 0 10px;
          font-size: 20px;
        }
      }
    }
  }
}
</style>
